package org.musicguardian.gui;

import java.io.File;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.musicguardian.core.Core;
import org.musicguardian.core.jobs.JobDirectoryScanner;
import org.musicguardian.core.scan.local.DirectoryScanner;

public class MessagePopupAction extends Action {

	private final IWorkbenchWindow window;

	MessagePopupAction(String text, IWorkbenchWindow window) {
		super(text);
		this.window = window;
		// The id is used to refer to the action in a menu or toolbar
		setId(ICommandIds.CMD_OPEN_MESSAGE);
		// Associate the action with a pre-defined command, to allow key
		// bindings.
		setActionDefinitionId(ICommandIds.CMD_OPEN_MESSAGE);
		setImageDescriptor(org.musicguardian.gui.Activator
				.getImageDescriptor("/icons/sample3.gif"));
	}

	public void run() {
		DirectoryDialog openDialog = new DirectoryDialog(window.getShell(),
				SWT.OPEN);
		String path = openDialog.open();
		if (path == null)
			return;
		JobDirectoryScanner jobScanner = new JobDirectoryScanner(new File(path));
		window.getWorkbench().getProgressService().showInDialog(
				window.getShell(), jobScanner);
		jobScanner.schedule();
	}
}